/**
 * 
 */
package vue.popup;

import vue.session.IGPreprocessorBlock;
import controller.ISessionManager;

/**
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class JPopupPreprocessor extends JPopupExecution {
	private static final long	serialVersionUID	= 1L;

	private IGPreprocessorBlock	preproc;

	/**
	 * Create a {@link JPopupPreprocessor}.
	 * 
	 * @param preproc
	 *            {@link IGPreprocessorBlock} associate
	 * @param manager
	 *            the session manager
	 */
	public JPopupPreprocessor(IGPreprocessorBlock preproc, ISessionManager manager) {
		super(null, manager);

		this.preproc = preproc;

		// createMenu();

		refresh();
	}

	@Override
	public void refresh() {
		super.refresh();

		if (preproc.getPreproc().getRes() == null)
		{// pas de res
			out.setEnabled(false);
			err.setEnabled(false);
		}
		else
		{// result dispo
			if (preproc.getPreproc().getRes().getStdin() != null)
				out.setEnabled(true);
			else
				out.setEnabled(false);
			if (preproc.getPreproc().getRes().getStderr() != null)
				err.setEnabled(true);
			else
				err.setEnabled(false);
		}
	}

	@Override
	public void showStdout() {
		new IGOutFrame(TITLE_OUT + preproc.getPreproc().getDescritpion(), getStdout());
	}

	@Override
	public void showStderr() {
		new IGOutFrame(TITLE_ERR + preproc.getPreproc().getDescritpion(), getStderr());
	}

	@Override
	public void removeFromSession() {
		manager.removeExecution(preproc.getPreproc());
	}

	@Override
	public String getStderr() {
		return preproc.getPreproc().getRes().getStderr();
	}

	@Override
	public String getStdout() {
		return preproc.getPreproc().getRes().getStdin();
	}
}
